﻿<!doctype html public '-//W3C//DTD HTML 4.0 Transitional //EN'>
<html>
<head>
<title>README</title>
<meta charset='UTF-8' />
<meta name='generator' content='EverEdit' />
<link href='D:\Program Files\everedit\mode\markdown\default.css' rel='stylesheet'></link>
<link href='D:\Program Files\everedit\mode\markdown\prettify.css' rel='stylesheet'></link>
<script type='text/javascript' src='D:\Program Files\everedit\mode\markdown\prettify.js'></script>
<script type='text/javascript' src='D:\Program Files\everedit\mode\markdown\jquery-1.10.2.min.js'></script>
<script type='text/javascript' src='D:\Program Files\everedit\mode\markdown\toc.js'></script>
</head>
<body>
<div id='generated-toc'></div>
<h1>C++ Option Parser</h1>

<p>import project from sourceforge <a href="https://sourceforge.net/projects/optionparser/">optionparser</a></p>

<p>Documentation is <a href="http://optionparser.sourceforge.net/">here</a></p>

<h2>Example</h2>

<pre><code>#include &lt;iostream&gt;
#include "optionparser.h"

enum  optionIndex { UNKNOWN, HELP, PLUS };
const option::Descriptor usage[] =
{
    {UNKNOWN, 0,"" , ""    ,option::Arg::None, "USAGE: example [options]\n\n"
                                            "Options:" },
    {HELP,    0,"" , "help",option::Arg::None, "  --help  \tPrint usage and exit." },
    {PLUS,    0,"p", "plus",option::Arg::None, "  --plus, -p  \tIncrement count." },
    {UNKNOWN, 0,"" ,  ""   ,option::Arg::None, "\nExamples:\n"
                                            "  example --unknown -- --this_is_no_option\n"
                                            "  example -unk --plus -ppp file1 file2\n" },
    {0,0,0,0,0,0}
};

int main(int argc, char* argv[])
{
    argc-=(argc&gt;0); argv+=(argc&gt;0); // skip program name argv[0] if present
    option::Stats  stats(usage, argc, argv);
    option::Option options[stats.options_max], buffer[stats.buffer_max];
    option::Parser parse(usage, argc, argv, options, buffer);

    if (parse.error())
        return 1;

    if (options[HELP] || argc == 0)
    {
        option::printUsage(std::cout, usage);
        return 0;
    }

    std::cout &lt;&lt; "--plus count: " &lt;&lt; options[PLUS].count() &lt;&lt; "\n";

    for (option::Option* opt = options[UNKNOWN]; opt; opt = opt-&gt;next())
        std::cout &lt;&lt; "Unknown option: " &lt;&lt; opt-&gt;name &lt;&lt; "\n";

    for (int i = 0; i &lt; parse.nonOptionsCount(); ++i)
        std::cout &lt;&lt; "Non-option #" &lt;&lt; i &lt;&lt; ": " &lt;&lt; parse.nonOption(i) &lt;&lt; "\n";
}
</code></pre>
<script type='text/javascript'>
$(document).ready(function(){
  if($('code').length>0){
    $('code').parent().addClass('prettyprint linenums');
    prettyPrint();
};
});
</script>
</body>
</html>